using System;
using System.Globalization;
using System.Windows.Data;
using CPlatePrintSys.Domain.Enums;

namespace CPlatePrintSys.Application.Converters
{
    public class UserRoleToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is UserRole role)
            {
                switch (role)
                {
                    case UserRole.User:
                        return "普通用户";
                    case UserRole.Admin:
                        return "管理员";
                    case UserRole.SuperAdmin:
                        return "超级用户";
                    default:
                        return role.ToString();
                }
            }
            return value?.ToString() ?? string.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string stringValue)
            {
                switch (stringValue)
                {
                    case "普通用户":
                        return UserRole.User;
                    case "管理员":
                        return UserRole.Admin;
                    case "超级用户":
                        return UserRole.SuperAdmin;
                    default:
                        return UserRole.User;
                }
            }
            return UserRole.User;
        }
    }
} 